package com.my.lock.v5;

import java.util.ArrayList;
import java.util.List;

public class PrimitiveOperation {

    public static void main(String[] args) throws Exception {
        Counter counter = new Counter(0);

        List<Thread> threads = new ArrayList<>();

        for (int i = 0; i < 3000; i++) {
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    counter.increment();
                }
            });
            threads.add(thread);
            thread.start();
        }

        for (Thread thread : threads) {
            thread.join();
        }

        System.out.println(counter.value);
    }


    private static class Counter {
        private int value;

        public Counter(int value) {
            this.value = value;
        }

        public void increment() {
            this.value += 1;
            this.value += 1;
            this.value += 1;
        }
    }
}

